/*
 * TableListController.java		1.00	2008. 01. 15
 *
 * Copyright (c) 2008 David.Kim(KJS). All Rights Reserved.
 * 
 * This software is the confidential and proprietary information
 * of David.Kim(KJS).  You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the license agreement
 * you entered into with David.Kim(KJS).
 */
package doit.gen.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import doit.framework.util.Config;
import doit.gen.domain.KeyValue;
import doit.gen.service.TableService;
import doit.gen.util.Generator;

/**
 * <pre>
 * system      : 
 * menu        : 
 * source      : TableController.java
 * description : 
 * </pre> 
 * @version
 * <pre> 
 * 1.0	2008. 01. 16  monolist 
 * 1.1	
 * </pre>
 */

@SuppressWarnings("unchecked")
public class TableController extends AbstractController {
	
	@Autowired
	private TableService tableService;
	
	private String view;
	
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map model = new HashMap();
		Map map = new HashMap();
		
		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		if (classLoader == null)
			classLoader = Generator.class.getClassLoader();
		
		if (request.getParameter("search") != null && !request.getParameter("search").equals("")) 
			map.put("searchValue",request.getParameter("search").toUpperCase());
		
		List output = tableService.getTables(map);
		model.put( "output", output);
		
		model.put("filePath", Config.getString("doit.generator.path.base"));
		
		List userSettingList = new Vector();
		String userSettings[] = Config.getString("doit.generator.type").split(",");
		for (int i = 0 ; i < userSettings.length ; i++) {
			String temp[] = userSettings[i].split(":");
			KeyValue keyValue = new KeyValue();
			keyValue.setKey(temp[1]);
			keyValue.setValue(temp[0]);
			userSettingList.add(keyValue);
		}
		model.put("userSettingList", userSettingList);
		
		return new ModelAndView( this.view, model);
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}
}
